package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.sensitive.SensitiveConfigVO;
import com.qumitech.visualnovel.controller.vo.sensitive.SensitiveUpdateVO;
import com.qumitech.visualnovel.service.sensitiveWord.SensitiveWordConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/sensitive")
public class SensitiveWordConfigController {

    @Autowired
    private SensitiveWordConfigService sensitiveWordConfigService;

    @GetMapping(value = "")
    public BaseRsp listSensitiveWordConfig(@RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                           @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                           @RequestParam(value = "state", required = false) Integer state,
                                           @RequestParam(value = "appId", required = false) String appId,
                                           @RequestParam(value = "category",required = false) String category,
                                           @RequestParam(value = "word", required = false) String word) {
        return new BaseRsp(ResultEnum.SUCCESS, sensitiveWordConfigService.listSensitiveWordConfigVO(offset,limit,state,appId,category,word));
    }

    @PostMapping(value = "")
    public BaseRsp saveSensitiveWordConfig(@RequestBody SensitiveConfigVO sensitiveConfigVO) {
        sensitiveWordConfigService.saveSensitiveWordConfig(sensitiveConfigVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PutMapping(value = "/{sensitive_id}")
    public BaseRsp updateSensitiveWordConfig(@RequestBody SensitiveUpdateVO sensitiveUpdateVO, @PathVariable(name = "sensitive_id") Long sensitiveId) {
        sensitiveUpdateVO.setId(sensitiveId);
        sensitiveWordConfigService.updateSensitiveWordConfig(sensitiveUpdateVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @DeleteMapping(value = "/{sensitive_id}")
    public BaseRsp rmSensitiveWordConfig(@PathVariable(name = "sensitive_id") Long sensitiveId,
                                         @RequestParam(value = "appId", required = false) String appId) {
        sensitiveWordConfigService.rmSensitiveWordConfig(sensitiveId, appId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

}
